//
//  ZYFinancialContentTypeViewController.m
//  HengYouCai
//
//  Created by 子壹财富 on 2018/11/8.
//  Copyright © 2018年 lwj. All rights reserved.
//

#import "ZYFinancialContentTypeViewController.h"
#import "HengYouCai-Swift.h"
@interface ZYFinancialContentTypeViewController ()<PageTitleViewDelegate,PageContentViewDelegate>
/**
 标题栏
 */
@property(nonatomic, retain)PageTitleView *pageTitleView;

/**
 内容
 */
@property(nonatomic, retain)PageContentView *pageContentView;
/**
 标题
 */
@property(nonatomic, retain)NSMutableArray *titles;
/**
 内容VC
 */
@property(nonatomic, retain)NSMutableArray *contents;

@end

@implementation ZYFinancialContentTypeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.titles = [NSMutableArray array];
    self.contents = [NSMutableArray array];
    [self getTypeList];
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = true;
   
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBar.hidden  = false;
    
}
- (void)getTypeList
{
    //    [self.view showHUDLoading];
    WLGetWeakSelf(weakSelf, self);
    
    static NSMutableArray *caceshResult = nil;
    if (caceshResult.count) {
        for (NSDictionary *typeDic in caceshResult) {
            
            ZYFinancialFroductListVC *couponDetail =  [[ZYFinancialFroductListVC alloc] init];
            [weakSelf.contents addObject:couponDetail];
            [weakSelf.titles addObject:typeDic[@"name"]];
            couponDetail.type = typeDic[@"id"];
        }
        [self setUI];
        
    }else{
        
        [self.view showHUDLoading];
        [HYCNetService productsGenreListOnSuccess:^(NSDictionary *dictResult) {
            [weakSelf.view hideHUDLoading:0];
            NSArray *arr = dictResult[@"productsGenreVoList"];
            caceshResult = [[NSMutableArray alloc] initWithArray:arr];
            for (NSDictionary *typeDic in arr) {
                
                ZYFinancialFroductListVC *couponDetail =  [[ZYFinancialFroductListVC alloc] init];
                [weakSelf.contents addObject:couponDetail];
                [weakSelf.titles addObject:typeDic[@"genreTitle"]];
                couponDetail.type = typeDic[@"id"];
            }
            [weakSelf setUI];
        } andFailed:^(NSInteger code, NSString *errorMsg) {
           [weakSelf.view showHUDFailTips:errorMsg hideDelay:kHUDHideDelay];
        }];
    }
}
/**
 初始化界面
 */
- (void)setUI
{
    self.automaticallyAdjustsScrollViewInsets = NO;
    [self.view addSubview:self.pageTitleView];
    [self.view addSubview:self.pageContentView];

}
#pragma PageTitleViewDelegate
- (void)pageTitleView:(PageTitleView *)titleView selectedIndex:(NSInteger)index
{
    [_pageContentView setCurrentIndex:index];
}
#pragma PageContentViewDelegate

- (void)pageContentView:(PageContentView *)contentView progress:(CGFloat)progress sourceIndex:(NSInteger)sourceIndex targetIndex:(NSInteger)targetIndex
{
    [_pageTitleView setTitleWithProgress:progress sourceIndex:sourceIndex targetIndex:targetIndex];
}
#pragma 懒加载
- (PageTitleView *)pageTitleView
{
    if (!_pageTitleView) {
        
        /**
         标题栏
         */
        _pageTitleView = [[PageTitleView alloc] initWithFrame:CGRectMake(0, kJcwStatuBarHeight(), f_Device_w, 44) titles:self.titles];
        _pageTitleView.delegate = self;
        _pageTitleView.backgroundColor = [UIColor whiteColor];
    }
    return _pageTitleView;
}
- (PageContentView *)pageContentView
{
    if (!_pageContentView) {
        /**
         内容
         */
        CGRect rect = CGRectMake(0,kJcwGetNavHeight(), f_Device_w, f_Device_h-(kJcwGetNavHeight()-SafeAreaInsetsWithBottom()));
        _pageContentView = [[PageContentView alloc] initWithFrame:rect childVcs:_contents parentViewController:self];
        _pageContentView.delegate = self;
    }
    return _pageContentView;
}


@end
